package com.hkts.naturalgas.association.controller;


import com.hkts.naturalgas.config.datahandler.EnviromentConstance;
import com.hkts.naturalgas.dictionaries.entity.HktsEnvironmentProtectionDictionaries;
import com.hkts.naturalgas.dictionaries.entity.HktsEnvironmentProtectionItem;
import com.hkts.naturalgas.dictionaries.service.IHktsEnvironmentProtectionDictionariesService;
import com.hkts.naturalgas.dictionaries.service.IHktsEnvironmentProtectionItemService;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.hkts.naturalgas.utils.CustomPageUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hkts.naturalgas.association.service.IHktsRequestAddressAssociationService;
import com.hkts.naturalgas.association.entity.HktsRequestAddressAssociation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yck
 * @since 2023-02-26
 */
@RestController
@RequestMapping("/instrumentdata/hktsRequestAddressAssociation")
public class HktsRequestAddressAssociationController {
    private final Logger logger = LoggerFactory.getLogger(HktsRequestAddressAssociationController.class);

    @Autowired
    public IHktsRequestAddressAssociationService iHktsRequestAddressAssociationService;

    @Autowired
    public IHktsEnvironmentProtectionDictionariesService iHktsEnvironmentProtectionDictionariesService;

    @Autowired
    public IHktsEnvironmentProtectionItemService iHktsEnvironmentProtectionItemService;

    /**
     * 分页查询数据
     *
     * @param page                          分页信息
     * @param hktsRequestAddressAssociation 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsRequestAddressAssociationPageList")
    public Result<Object> getHontUserList(Page<HktsRequestAddressAssociation> page, HktsRequestAddressAssociation hktsRequestAddressAssociation) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsRequestAddressAssociationService.selectPage(page, hktsRequestAddressAssociation)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsRequestAddressAssociation 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsRequestAddressAssociationSave")
    public Result<Object> hktsRequestAddressAssociationSave(HktsRequestAddressAssociation hktsRequestAddressAssociation) {
        iHktsRequestAddressAssociationService.saveOrUpdate(hktsRequestAddressAssociation);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsRequestAddressAssociationGetById")
    public Result<Object> hktsRequestAddressAssociationGetById(String id) {
        HktsRequestAddressAssociation byId = iHktsRequestAddressAssociationService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsRequestAddressAssociationDelete")
    public Result<Object> hontUserDelete(String id) {
        iHktsRequestAddressAssociationService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsRequestAddressAssociationBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsRequestAddressAssociationService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }


    /*@ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getTestTlData")
    public Result<Object> testData() {
        HktsEnvironmentProtectionDictionaries hktsEnvironmentProtectionDictionaries = iHktsEnvironmentProtectionDictionariesService.getDbTable();
        List<HktsEnvironmentProtectionItem> hktsEnvironmentProtectionItems = iHktsEnvironmentProtectionItemService.getDbTable();
        List<String> list = new ArrayList<>();
        List<String> listFiled = new ArrayList<>();
        for (int i = 0; i < hktsEnvironmentProtectionItems.size(); i++) {
            if (!hktsEnvironmentProtectionItems.get(i).getDataType().equals(EnviromentConstance.DATE_TIME)) {
                list.add(hktsEnvironmentProtectionItems.get(i).getFieldName());
                listFiled.add(hktsEnvironmentProtectionItems.get(i).getCorrespondingField());
            }
        }
        *//*Map<String, Object> associations = iHktsRequestAddressAssociationService.getAssociations(hktsEnvironmentProtectionDictionaries, list, listFiled);*//*
        return ResultUtil.data(associations);
    }*/

}
